package com.niit.musicserve.exception;

import com.niit.musicserve.utils.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.sql.SQLException;

@ControllerAdvice
public class GlobalExceptionHandler {
    
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result<Void> handleException(Exception e) {
	    
        return Result.error("系统错误"+e.getMessage());
    }
    
    @ExceptionHandler(SQLException.class)
    @ResponseBody
    public Result<Void> handleSQLException(SQLException e) {
	   
	return Result.error("数据库错误"+e.getMessage());
    }
    
    @ExceptionHandler(IllegalArgumentException.class)
    @ResponseBody
    public Result<Void> handleIllegalArgumentException(IllegalArgumentException e) {
	    
        return Result.error("参数错误"+e.getMessage());
    }
}
